package com.sunmnet.j2ee.action.powerdb.designer;

import com.sunmnet.j2ee.action.BaseAction;
import com.sunmnet.j2ee.bean.pub.action.JsonResult;
import com.sunmnet.j2ee.core.pub.annotation.MethodName;
import com.sunmnet.j2ee.service.powerdb.designer.PDMService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <PRE>
 * pdm设计模块
 * </PRE>
 * <B>项    目：</B> sunmnet-j2ee
 * <B>技术支持：</B>广东三盟科技 (c)
 *
 * @author 黄坚：huangj@sunmnet.com
 * @version 1.0
 * @since jdk版本：jdk1.7
 */
@Controller("/powerdb/designer/pdm")
@RequestMapping("/powerdb/designer/pdm")
public class PDMAction {

	/**
	 * log4j2日志 *
	 */
	private static final Logger LOG = LogManager.getLogger(PDMAction.class.getName());

	@Resource(name = "/powerdb/designer/pdmService")
	private PDMService service;

	/**
	 * 获取图形数据
	 *
	 * @param moduleId 模块编码
	 * @param request  HttpServletRequest
	 * @return JsonResult
	 */
	@MethodName(name = "获取图形数据")
	@RequestMapping(value = "/getChart", method = RequestMethod.POST)
	@ResponseBody
	public JsonResult getChart(@RequestParam(value = "moduleId", required = true) Long moduleId,
	                           @RequestParam(value = "versionId", required = false) Long versionId,
	                           HttpServletRequest request) {
		JsonResult js = new JsonResult();
		try {
			js.setObj(service.getChart(moduleId, versionId));

		} catch (Exception e) {
			BaseAction.setErrMsg("", LOG, js, e);
		}

		return js;
	}

	/**
	 * 更新图形的坐标数据
	 *
	 * @return JsonResult
	 */
	@MethodName(name = "更新图形的坐标数据")
	@RequestMapping(value = "/updateChart", method = RequestMethod.POST)
	@ResponseBody
	public JsonResult updateChart(@RequestParam(value = "jsonEntitys", required = true) String jsonEntitys,
	                              @RequestParam(value = "jsonRelates", required = true) String jsonRelates,
	                              HttpServletRequest request) {
		JsonResult js = new JsonResult();
		try {
			service.updateChart(jsonEntitys, jsonRelates);
			js.setObj(1);

		} catch (Exception e) {
			BaseAction.setErrMsg("更新图形的坐标数据失败", LOG, js, e);
		}

		return js;
	}

}

